home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_3.lha
/
7_3
/
7_3a.c
next >
Wrap
Text File
|
1993-08-08
|
1KB
|
102 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ exercise 7.3
lass triangle: public shape
point sw, se, top;
int UP()
{
return (top.y >= se.y) ?
( (top.y >= sw.y) ? top.y : sw.y ) :
(se.y >= sw.y) ? se.y : sw.y;
}
int RIGHT()
{
return (top.x >= se.x) ?
( (top.x >= sw.x) ? top.x : sw.x ) :
(se.x >= sw.x) ? se.x : sw.x;
}
int DOWN()
{
return (top.y <= se.y) ?
( (top.y <= sw.y) ? top.y : sw.y ) :
(se.y <= sw.y) ? se.y : sw.y;
}
int LEFT()
{
return (top.x <= se.x) ?
( (top.x <= sw.x) ? top.x : sw.x ) :
(se.x <= sw.x) ? se.x : sw.x;
}
ublic:
triangle(point a, point b, point c)
{
sw = a; top = b; se = c;
}
void move(int x, int y)
{
sw.x += x;
sw.y += y;
top.x += x;
top.y += y;
se.x += x;
se.y += y;
}
void draw()
{
put_line(sw, top);
put_line(top, se);
put_line(se, sw);
}
point north()
{
return point((LEFT() + RIGHT()) / 2, UP());
}
point south()
{
return point((LEFT() + RIGHT()) / 2, DOWN());
}
point east()
{
return point(LEFT(), (UP() + DOWN()) / 2);
}
point west()
{
return point(RIGHT(), (UP() + DOWN()) / 2);
}
point swest()
{
return point(LEFT(), DOWN());
}
point seast()
{
return point(RIGHT(), DOWN());
}
point nwest()
{
return point(LEFT(), UP());
}
point neast()
{
return point(RIGHT(), UP());
}
;